package cn.wzptsoft.tinymallbe.controller;

import cn.wzptsoft.common.utils.JwtUtils;
import cn.wzptsoft.common.utils.Result;
import cn.wzptsoft.tinymallbe.entity.Address;
import cn.wzptsoft.tinymallbe.entity.Theme;
import cn.wzptsoft.tinymallbe.entity.User;
import cn.wzptsoft.tinymallbe.entity.UserLoginDTO;
import cn.wzptsoft.tinymallbe.service.AddressService;
import cn.wzptsoft.tinymallbe.service.ThemeService;
import cn.wzptsoft.tinymallbe.vo.TokenVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    //    根据用户找到地址
    @PostMapping("/addres")
    public Result<List<Address>> addres(Integer userid){
        List<Address> users= addressService.addres(userid);
        return Result.ok(users);
    }

    //    添加地址
    @PostMapping("/add")
    public Result<Address> add(Address address){
        Address users= addressService.add(address);
        return Result.ok(users);
    }
    //    修改地址
    @PostMapping("/updata")
    public Result<Address> updata(Address form){
        Address users= addressService.updata(form);
        return Result.ok(users);
    }
//        删除地址
    @PostMapping("/delete")
    public Result<String> delete(Long id){
        return  Result.ok(addressService.delete(id));
    }
}
